﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Business;
using Dto;

namespace YaoYunDong.Controllers
{
    public class MovingController : Controller
    {
        private readonly MovingBusiness movingBusiness = new MovingBusiness();

        public ActionResult SaveMoving(string content, string groupCode)
        {
            var userInfo = System.Web.HttpContext.Current.Session["User"] as UsersDto;
            if (userInfo != null)
            {
                var movingDto = new UserMovingDto
                                    {
                                        MovingContent = content,
                                        MovingId = 0,
                                        MovingTime = DateTime.Now,
                                        MovingUserId = userInfo.UserId
                                    };
                var b = movingBusiness.Save(movingDto);
                if (b)
                {
                    Response.Write("<script>alert('发表动态成功！');location.href='" +
                                   Url.Action("Index", "Group", new { code = groupCode }) + "';</script>");
                    Response.End();
                }
            }
            else
            {
                Response.Write("<script>alert('请先登录！');location.href='" +
                                   Url.Action("Index", "Channel", new { channelCode = "yqzb" }) + "';</script>");
                Response.End();
            }
            return RedirectToAction("Index", "Group", new { code = groupCode });
        }
    }
}
